package com.tanhua.server.controller;

import com.tanhua.manage.domain.vo.CommentVo;
import com.tanhua.manage.domain.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;

/**
 * 通过动态id查询评论列表
 */
    @GetMapping
    public ResponseEntity findPage(String movementId, @RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10") Long pageSize){
        PageResult<CommentVo> pageResult = commentService.findPage(movementId,page,pageSize);
        System.out.println("hahahahahha");
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发表评论
     */
    @PostMapping
    public ResponseEntity add(@RequestBody Map<String,String> paramMap){
        commentService.add(paramMap);
        return ResponseEntity.ok(null);
    }

    /**
     * 点赞评论
     * @param commentId
     * @return
     */
    @GetMapping("/{commentId}/like")
    public ResponseEntity like(@PathVariable String commentId){

        Long likeCount = commentService.likeComment(commentId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 取消点赞评论
     * @param commentId
     * @return
     */
    @GetMapping("/{commentId}/dislike")
    public ResponseEntity dislike(@PathVariable String commentId){
        Long likeCount = commentService.dislikeComment(commentId);
        return ResponseEntity.ok(likeCount);
    }
}
